//
//  BQOrderTableVC.m
//  BeeQuick
//
//  Created by Vivitickey on 2017/5/6.
//  Copyright © 2017年 test. All rights reserved.
//

#import "BQOrderTableVC.h"
#import "BQmyOrderModel.h"
//#import "BQorderOpinionModel.h"
#import "BQFirstCell.h"
#import "BQSecondCell.h"
#import "BQThirdCell.h"
#import "BQFourthCell.h"
@interface BQOrderTableVC ()

@end

static NSString *first_cell = @"first_cell";
static NSString *second_cell = @"second_cell";
static NSString *third_cell = @"third_cell";
static NSString *fourth_cell = @"fourth_cell";

@implementation BQOrderTableVC{
    
    NSArray *_dataArray;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self loadData];
    
    self.navigationItem.title = @"我的订单";
    
    
    
    UIImage *image =[UIImage imageNamed:@"v2_goback-1"];
    UIButton *btn =[[UIButton alloc]init];
    [btn  setBackgroundImage:image forState:UIControlStateNormal];
    btn.frame =CGRectMake(0, 0, 24, 24);
    
    UIBarButtonItem *button =[[UIBarButtonItem alloc]initWithCustomView:btn];
    [btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem =button;
    
    
    
    [self.tableView registerNib:[UINib nibWithNibName:@"BQFirstCell" bundle:nil]forCellReuseIdentifier:first_cell];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"BQSecondCell" bundle:nil]forCellReuseIdentifier:second_cell];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"BQThirdCell" bundle:nil]forCellReuseIdentifier:third_cell];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"BQFourthCell" bundle:nil]forCellReuseIdentifier:fourth_cell];
 
    
    
}

-(void)click{
    
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)viewWillAppear:(BOOL)animated {
    
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return _dataArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 4;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 0) {
        BQFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:first_cell forIndexPath:indexPath];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        cell.model = _dataArray[indexPath.section];
        
        return cell;
    }else if(indexPath.row == 1){
        BQSecondCell *cell = [tableView dequeueReusableCellWithIdentifier:second_cell forIndexPath:indexPath];
    
        BQmyOrderModel *OrderModel = _dataArray[indexPath.section];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
        cell.model = OrderModel;
        return cell;
    }else if(indexPath.row == 2){
        BQThirdCell *cell = [tableView dequeueReusableCellWithIdentifier:third_cell forIndexPath:indexPath];
        
        
        
        BQmyOrderModel *model = _dataArray[indexPath.section];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        cell.model = model;
        
        return cell;
    }else{
        BQFourthCell *cell = [tableView dequeueReusableCellWithIdentifier:fourth_cell forIndexPath:indexPath];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
        
        
        return cell;
    }

}

-(void)loadData{
    
    NSDictionary *para = @{@"call" : @13};
    
    [_AccountMgr POSTWithUrlString:myOrder_url parameters:para success:^(id responseObject) {
        
        // 获取分类模型数组
        NSArray *dictArray = responseObject[@"data"];
        
        _dataArray = [NSArray yy_modelArrayWithClass:[BQmyOrderModel class] json:dictArray];
        

        
        [self.tableView reloadData];
        
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
    
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 1) {
        return 70;
    }else if(indexPath.row == 3){
        
        return 40;
        
    }
    return 30;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 20;
    
}
@end
